<!--{template header,admin}-->
<script src="js/jquery.js" type="text/javascript"></script>
<script src="js/admin.js" type="text/javascript"></script>
<script src="js/dialog.js" type="text/javascript"></script>
<div style="width:100%; height:15px;color:#000;margin:0px 0px 10px;">
    <div style="float:left;"><a href="index.php?admin_main/stat{$setting['seo_suffix']}" target="main"><b>控制面板首页</b></a>&nbsp;&raquo;&nbsp;专家管理</div>
</div>
<!--{if isset($message)}-->
<!--{eval $type=isset($type)?$type:'correctmsg'; }-->
<table cellspacing="1" cellpadding="4" width="100%" align="center" class="tableborder">
    <tr>
        <td class="{$type}">{$message}</td>
    </tr>
</table>
<!--{/if}-->
<form action="index.php?admin_expert/add{$setting['seo_suffix']}" method="post" onsubmit="return checkform(this);">
    <table width="100%" cellspacing="1" cellpadding="4" align="center" class="tableborder">
        <tbody>
            <tr class="header" ><td colspan="3">专家管理</td></tr>
            <tr class="altbg1"><td colspan="3">1、用户名必须是系统已注册用户。2、分类为系统已添加分类，多个分类用,隔开,最多不超过3个</td></tr>
            <tr>
                <td width="30%" >用户名:<input type="text" name="username"/></td>
                <td  width="40%">擅长分类ID:<input type="text" name="goodatcategory" id="categorys" size="50" onfocus="showselect()"/></td>
                <td  width="30%"><input class="button" type="submit" value="提 交" ></td>
            </tr>
        </tbody>
    </table>
</form>
<form action="index.php?admin_expert/remove{$setting['seo_suffix']}" method="post">
    <table width="100%" border="0" cellpadding="4" cellspacing="1" class="tableborder">
        <tr class="header">
            <td width="10%"><input class="checkbox" id="chkall" onclick="checkall('delete[]')" type="checkbox" name="chkall"><label for="chkall">删除</label></td>
            <td  width="40%">用户名</td>
            <td  width="50%">擅长分类</td>
        </tr>
        <!--{loop $expertlist $expert}-->
        <tr>
            <td width="20" class="altbg2"><input class="checkbox" type="checkbox" value="{$expert['uid']}" name="delete[]"></td>
            <td width="300" class="altbg2"><strong>{$expert['username']}</strong></td>
            <td width="100" class="altbg2">{$expert['categoryname']}</td>
        </tr>
        <!--{/loop}-->
        <tr class="altbg1"><td colspan="3" class="altbg1"  align="left"><input type="submit" name="submit" class="button" value="提&nbsp;交" /></td></tr>
    </table>
</form>
<br>
<div id="ulid" style="display: none"></div>
<script type="text/javascript">
    var sortobj=eval('($category_js)');
    var g_ClassLevel1;
    var g_ClassLevel2;
    var g_ClassLevel3;
    var class_level_1=sortobj.category1;
    var class_level_2=sortobj.category2;
    var class_level_3=sortobj.category3;
    var button_noselect="不选择";

    function getCidValue()
    {
        var _cl1 = document.askform.ClassLevel1;
        var _cl2 = document.askform.ClassLevel2;
        var _cl3 = document.askform.ClassLevel3;
        var _cid = document.askform.cid;
        if(_cl1.value!=0) _cid.value = _cl1.value;
        if(_cl2.value!=0) _cid.value = _cl2.value;
        if(_cl3.value!=0) _cid.value = _cl3.value;
    }
    function FillClassLevel1(ClassLevel1)
    {
        ClassLevel1.options[0] = new Option("aa", "0");
        for(i=0; i<class_level_1.length; i++)
        {
            ClassLevel1.options[i] = new Option(class_level_1[i][1], class_level_1[i][0]);
        }
        // ClassLevel1.options[0].selected = true;
        ClassLevel1.length = i;
    }
    function FillClassLevel2(ClassLevel2, class_level_1_id)
    {
        ClassLevel2.options[0] = new Option(button_noselect, "");
        count = 1;
        for(i=0; i<class_level_2.length; i++){
            if(class_level_2[i][0].toString() == class_level_1_id) {
                ClassLevel2.options[count] = new Option(class_level_2[i][2], class_level_2[i][1]);
                count = count+1;}
        }
        ClassLevel2.options[0].selected = true;
        ClassLevel2.length = count;
    }
    function FillClassLevel3(ClassLevel3, class_level_2_id)
    {
        ClassLevel3.options[0] = new Option(button_noselect, "");
        count = 1;
        for(i=0; i<class_level_3.length; i++) {
            if(class_level_3[i][0].toString() == class_level_2_id) {
                ClassLevel3.options[count] = new Option(class_level_3[i][2], class_level_3[i][1]);
                count = count+1;}
        }
        ClassLevel3.options[0].selected = true;
        ClassLevel3.length = count;
    }
    function ClassLevel2_onchange()
    {
        getCidValue();
        FillClassLevel3(g_ClassLevel3, g_ClassLevel2.value);
        if (g_ClassLevel3.length <= 1) {
            g_ClassLevel3.style.display = "none";
            document.getElementById("jiantou").style.display = "none";
        }
        else {
            g_ClassLevel3.style.display = "";
            document.getElementById("jiantou").style.display = "";
        }
    }
 
    function ClassLevel1_onchange()
    {
        getCidValue();
        FillClassLevel2(g_ClassLevel2, g_ClassLevel1.value);
        ClassLevel2_onchange();
	
    }
    function InitClassLevelList(ClassLevel1, ClassLevel2, ClassLevel3)
    {
        g_ClassLevel1=ClassLevel1;
        g_ClassLevel2=ClassLevel2;
        g_ClassLevel3=ClassLevel3;
        g_ClassLevel1.onchange = Function("ClassLevel1_onchange();");
        g_ClassLevel2.onchange = Function("ClassLevel2_onchange();");
        FillClassLevel1(g_ClassLevel1);
        ClassLevel1_onchange();
    }

    function checkform(form){
        var username = form.username.value;
        var goodatcate = form.goodatcategory.value;
        if(username == '' || goodatcate == '' ){
            alert("用户名或分类不能为空");
            return false;
        }
        return true;
    }

    function showselect(){
 
        var select = $("#selectcategory").html();
        $.dialog({
            id:'addreason',
            position:'center',
            align:'left',
            width:600,
            height:200,
            title:'选择专家擅长分类',
            fnOk:function(){ 
                var cids='';
                $("input[name='cids[]']").each(function(){
                    cids +=$(this).val()+' ';
                });
                $("#categorys").val(cids);
                $("#ulid").html($("#selectedcate").html());
                $.dialog.close('addreason');            
            },
            fnCancel:function(){$.dialog.close('addreason')},
            content:'已选中的分类：<br /><ul id="selectedcate"></ul><form name="askform" method="POST" action="index.php?adimin_expert/add">'+'<table border="0" cellpadding="0" cellspacing="0" width="100%">'+
                '<tr valign="top">'+
                '<td width="15%">'+
                '<select  id="ClassLevel1" class="catselect2" size="8" name="classlevel1" style="width:100%" >'+
                '<option selected></option>'+
                '</select>'+
                '</td>'+
                '<td align="center" valign="middle" width="3%">'+
                '<div><b>→</b></div>'+
                '</td>'+
                '<td width="15%">'+
                '<select  id="ClassLevel2"  class="catselect2" size="8" name="classlevel2" style="width:100%">'+
                '<option selected></option>'+
                '</select>'+
                '<td align="center" valign="middle" width="3%">'+
                '<div style="display: none;" id="jiantou"><b>→</b></div>'+
                '</td>'+
                '<td width="15%">'+
                '<select id="ClassLevel3"  class="catselect2" size="8" onchange="getCidValue();"  name="classlevel3" style="width:100%">'+
                '<option selected></option>'+
                '</select>'+
                '</td>'+
                '<td width="30%" valign="middle">&nbsp;<input type="button" value="添加分类" onclick="addcategory();" /></td>'+
                '</tr>'+
                '<tr valign="top">'+
                '<td class="tiw_biaozhu" colspan="6" align="left" valign="middle">所选分类不能重叠，不能相互包含！</td></tr>'+
                '</table>'+
                '<input type="hidden" value="0" name="cid" />'+
                '<input type="hidden" value="0" name="allcid" />'+
                '</form>'
        });
        InitClassLevelList(document.askform.ClassLevel1, document.askform.ClassLevel2, document.askform.ClassLevel3);
        var selected_id_list="0"
        var blank_pos = selected_id_list.indexOf(" ");
        var find_blank = true;
        if (blank_pos == -1) {
            find_blank = false;
            blank_pos = selected_id_list.length;
        }
        $("#selectedcate").html($("#ulid").html());
    }

    function addcategory(){
        var curcid = $("input[name='cid']").val();
        if(curcid == 0){
            alert("您还未选择分类！");
            return false;
        }
        $.ajax({
            type: "POST",
            url: "index.php?admin_expert/ajaxgetname.html",
            data: "cid="+curcid,
            success: function(categorystr){
                if($("#selectedcate li").size()<=2)
                    $("#selectedcate").append('<li style="color:#3F92F8;"><input type="hidden" name="cids[]"  value="'+curcid+'" />'+categorystr+'&nbsp;&nbsp;<a href="#" onclick="delcategory(this);">删除</a></li>');

            }
        });    
    }
    function delcategory(a){
        $(a).parent().remove();
        $("input[name='cid']").val("0");
    }
</script>
<!--{template footer,admin}-->


